package net.maku.module.organization.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.module.organization.convert.OrganizationConvert;
import net.maku.module.organization.convert.WorkplaceConvert;
import net.maku.module.organization.entity.OrganizationEntity;
import net.maku.newbase.NewBaseController;
import net.maku.module.organization.entity.WorkplaceEntity;
import net.maku.module.organization.service.WorkplaceService;
import net.maku.newbase.NewQuery;
import net.maku.newbase.PageParam;
import net.maku.newbase.R;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 工作地点
 *
 * @author JYL
 */
@RestController
@RequestMapping("nb/workplace")
@Tag(name = "工作地点")
@AllArgsConstructor
public class WorkplaceController extends NewBaseController<WorkplaceService, WorkplaceEntity> {

    /**
     * 查询 全部
     *
     * @return
     */
    @Operation(summary = "查询 全部")
    @RequestMapping(value = "findAll", method = RequestMethod.GET)
    public R findAll() {
        return R.ok(entityService.list());
    }

    /**
     * 分页查询
     *
     * @param page
     * @param query
     * @return
     */
    @Operation(summary = "分页")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result page(PageParam page, NewQuery query) {
        LambdaQueryWrapper<WorkplaceEntity> select = new LambdaQueryWrapper<>();

        IPage<WorkplaceEntity> iPage = entityService.page(page.b(), select);
        return Result.ok(new PageResult<>(WorkplaceConvert.INSTANCE.convertList(iPage.getRecords()), iPage.getTotal()));
    }

}
